package com.github.lee.mvvm.core.ui.web.view

import android.annotation.SuppressLint
import android.content.Context
import android.os.Build
import android.util.AttributeSet
import com.tencent.smtt.sdk.WebSettings
import com.tencent.smtt.sdk.WebView

class CustomizeWebView : WebView {

    constructor(context: Context?) : this(context, null)
    constructor(context: Context?, attr: AttributeSet?) : this(context, attr, 0)
    constructor(context: Context?, attr: AttributeSet?, style: Int) : super(context, attr, style){
        init()
    }


    @Suppress("DEPRECATION")
    @SuppressLint("SetJavaScriptEnabled")
    private fun init() {
        settings.apply {
            javaScriptEnabled = true
            javaScriptCanOpenWindowsAutomatically = true
            allowFileAccess = true
            layoutAlgorithm = WebSettings.LayoutAlgorithm.NARROW_COLUMNS

            setSupportZoom(false)
            builtInZoomControls = false

            useWideViewPort = true
            setSupportMultipleWindows(true)
            loadWithOverviewMode = true
            setAppCacheEnabled(true)
            databaseEnabled = true
            domStorageEnabled = true
            setGeolocationEnabled(true)
            setAppCacheMaxSize(Long.MAX_VALUE)
            pluginState =WebSettings.PluginState.ON
            setRenderPriority(WebSettings.RenderPriority.HIGH)
            cacheMode = WebSettings.LOAD_NO_CACHE
            mixedContentMode = android.webkit.WebSettings.MIXED_CONTENT_ALWAYS_ALLOW
        }
    }


}